package com.future.mayi.qsale.activity;

import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;

import com.future.baselib.entity.DefaultResponse;
import com.future.baselib.utils.ApiCst;
import com.future.baselib.utils.HttpRequest;
import com.future.mayi.R;
import com.future.mayi.activity.BaseActivity;
import com.future.mayi.utils.HtmlFormat;
import com.future.mayi.utils.Navigator;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/5/24.
 */

public class QuickSaleActivity extends BaseActivity {


    @BindView(R.id.btn_on_sale)
    ImageView btnOnSale;
    @BindView(R.id.btn_recycle)
    ImageView btnRecycle;
    @BindView(R.id.btn_close)
    ImageView btnClose;
    @BindView(R.id.web_recycle)
    WebView webRecycle;
    @BindView(R.id.web_sale)
    WebView webSale;

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_quick_sale);
        ButterKnife.bind(this);
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initDates() {
        new HttpRequest<DefaultResponse>()
                .with(this)
                .setApiCode(ApiCst.appRecyclerAndSale)
                .setListener(new HttpRequest.OnNetworkListener<DefaultResponse>() {
                    @Override
                    public void onSuccess(DefaultResponse response) {
                        try {
                            JSONObject object = new JSONObject(response.content);
                            String jimai = object.optString("jimai");
                            String huishou = object.optString("huishou");
                            if (webRecycle != null) {
                                webRecycle.loadDataWithBaseURL(null, HtmlFormat.getNewContent(huishou), "text/html", "utf-8", null);
                            }

                            if (webSale != null) {
                                webSale.loadDataWithBaseURL(null, HtmlFormat.getNewContent(jimai), "text/html", "utf-8", null);
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFail(String message, DefaultResponse response) {
                        toast(message);
                    }
                })
                .start(new DefaultResponse());
    }

    @Override
    protected void initListener() {


    }

    @OnClick({R.id.btn_on_sale, R.id.btn_recycle, R.id.btn_close})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_on_sale:
                Navigator.navigatorToConsignSaleActivity(this);
                break;
            case R.id.btn_recycle:
                Navigator.navigatorToRecycleActivity(this);
                break;
            case R.id.btn_close:
                this.finish();
                break;
        }
    }
}
